<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../../baseAdm.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns="http://www.w3.org/1999/xhtml">
    
    <ui:define name="content">

        <h:form id="form">
        

            <p:ajaxStatus style="width:16px;height:16px;">
                <f:facet name="start">
                    <h:graphicImage name="ajaxloading.gif" library="images" />
                </f:facet>

                <f:facet name="complete">
                    <h:outputText value="" />
                </f:facet>
            </p:ajaxStatus>
            <p:dataTable id="tabTipoUso" var="tipo" value="#{icmsFace.listaT}" 
                         selectionMode="single" emptyMessage="Nenhum registro encontrado."
                         height="50">

                <f:facet name="header" >Tipos de Usos
                </f:facet>

                <p:column sortBy="#{tipo.id}">
                    <f:facet name="header"><h:outputText value="Id"/></f:facet>
                    <h:outputText value="#{tipo.id}"/>
                </p:column>

                <p:column  sortBy="#{tipo.descricao}">
                    <f:facet name="header">Descrição</f:facet>
                    <h:outputText value="#{tipo.descricao}"/>
                </p:column>

                <p:column  sortBy="#{tipo.desconto}">
                    <f:facet name="header">Desconto</f:facet>
                    <h:outputText value="#{tipo.desconto}" >
                        <f:convertNumber type="percent"/>
                    </h:outputText>
                </p:column>

                <p:column  sortBy="#{tipo.descontoSegundoPosto}">
                    <f:facet name="header">Desconto Hor. Reservado</f:facet>
                    <h:outputText value="#{tipo.descontoSegundoPosto}" >
                        <f:convertNumber type="percent"/>
                        
                    </h:outputText>
                </p:column>

                <p:column>
                    <f:facet name="header">Ações</f:facet>
                    <p:commandButton image="ui-icon-pencil" update=":form:painel"
                                     oncomplete="conceDialog.show()" title="Editar" >
                        <f:setPropertyActionListener value="#{tipo}" target="#{icmsFace.selectedTipo}" />
                    </p:commandButton>

                    <p:commandButton image="ui-icon-trash" update=":form:painel"
                                     title="Excluir" oncomplete="confirmation.show()" >
                        <f:setPropertyActionListener value="#{tipo}" target="#{icmsFace.selectedTipo}" />
                    </p:commandButton>
                    
                </p:column>
                <f:facet name="footer" >
                    <p:commandButton image="ui-icon-disk" update=":form:painel"
                                     title="Novo" value="Novo" oncomplete="conceDialog.show()"
                                     action="#{icmsFace.doCreateTipo}"/>
                </f:facet>
            </p:dataTable>

            <p:dialog widgetVar="conceDialog" width="600" resizable="true"
                      id="conceDlg" header="Cadastro de Tipos de Usos" showEffect="explode"
                      hideEffect="slide">
                <p:outputPanel id="painel" rendered="true">
                    <script type="text/javascript">
                        (function($){
                            $(function(){
                                $('input:text').setMask();
                            });
                        })(jQuery);
                    </script>
                    <h:panelGrid columns="2"  >
                        <h:outputLabel value="Descrição:"/>
                        <p:inputText value="#{icmsFace.selectedTipo.descricao}" rendered="true" />

                        <h:outputLabel value="Desconto:"/>
                        <p:inputText id="idesc" value="#{icmsFace.selectedTipo.desconto}" alt="decimal" rendered="true" >
                            <f:convertNumber locale="pt_BR" minFractionDigits="2" />
                        </p:inputText>

                        <h:outputLabel value="Desconto hor. Reservado:"/>
                        <p:inputText id="idesc2" value="#{icmsFace.selectedTipo.descontoSegundoPosto}"
                                     rendered="true" alt="decimal" >
                            <f:convertNumber locale="pt_BR" minFractionDigits="2"/>
                        </p:inputText>

                        <p:commandButton value="Salvar" action="#{icmsFace.doFinishCreateTipo}"
                                         oncomplete="conceDialog.hide()" update="tabTipoUso">

                        </p:commandButton>
                        <p:commandButton value="Cancelar" oncomplete="conceDialog.hide()" action="#{icmsFace.resetIsNew}"/>
                    </h:panelGrid>

                </p:outputPanel>
            </p:dialog>

            <p:confirmDialog message="Você deseja realmente exluir este registro?" width="200"
                             showEffect="explode" hideEffect="explode"
                             header="Confirmação" severity="alert" widgetVar="confirmation" modal="true" >

                <p:commandButton value="Sim" update="tabTipoUso" action="#{icmsFace.doRemoveTipoUso()}"
                                 oncomplete="confirmation.hide()"/>
                <p:commandButton value="Não" onclick="confirmation.hide()" type="button" />

            </p:confirmDialog>
            <br></br>
        </h:form>
        <ui:include id="continua" src="cadICMS_1.xhtml"/>

    </ui:define>

</ui:composition>